package com.bawei.library_base.manager;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author : zhiyu
 * @date :
 * @content :单类类
 */
public class MyManager {

    private static volatile MyManager myManager;

    public static MyManager getInstance(){
        if (myManager==null){
            synchronized (MyManager.class){
                if (myManager==null){
                    myManager=new MyManager();
                }
            }
        }

        return myManager;
    }


    private Retrofit retrofit;
    public Retrofit getRetrofit(String url){
        if (retrofit==null){
            retrofit=new Retrofit.Builder()
                    .client(new OkHttpClient().newBuilder()
                            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                            .build())
                    .baseUrl(url)
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }

}
